<script type="text/x-red" data-template-name="panel_led_out">
    <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i>Pin-Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>

    <div class="form-row">
        <br>
        <label for=""><i class="fa fa-tag"></i> Panel type</label>
        <select type="text" id="node-input-select">
            <option value="NK2200">NK-2200</option>
        </select>
        <input type="hidden" id="node-input-type">
    </div>

    <div class="form-tips" id="node-tip">
      Please define your GPIO number. This are the rules:
      <table border="1"  cellpadding="2">
        <tr><td><strong>CPU Port</strong></td><td><strong>GPIO-number</strong></td></tr>
        <tr><td>PA0..PA31</td><td>0..31</td></tr>
        <tr><td>PB0..PB31</td><td>32..63</td></tr>
        <tr><td>PC0..PC31</td><td>64..95</td></tr>
        <tr><td>Pxy..</td><td>x*32+y</td></tr>
      </table>
    </div>

    <div class="form-row">
         <br>
        <input type="hidden" id="node-input-pin">               <!-- This is the place where phys. pin number is stored  -->
        <label><i class="fa fa-tag"></i> LED Pin</label> 
        <select type="text" id="node-input-pin10" style="width: 250px;" name="NK2200">
            <option value='' disabled selected style='display:none;'>select pin</option>
            <option value="G1A2">COM1_LED</option>
            <option value="G0B0">COM2_LED</option>
            <option value="G1A4">IR_LED</option>
            <option value="G1C7">IO_LED</option>
            <option value="G1A1">LAN_LED</option>
            <option value="G1A0">NET_LED</option>
         </select>
  
    </div>

    <div class="form-row" id="node-set-state">
        <label for="node-input-level">&nbsp;</label>
        <select id="node-input-level" style="width: 250px;">
            <option value="0"> low (0)</option>
            <option value="1"> high (1)</option>
        </select>
    </div>
  
  
</script>

<script type="text/x-red" data-help-name="panel_led_out">
    <p>GPIO output node for OrangePi and others..</p>
    <p>All GPIO-pins are available, regardless of their multiplex functions.</p>
    <p>Therefore, user is responsible to not disturb alternate pin functions.</p>
    <p><code>msg.payload</code> should be set to 1 or 0.</p>
</script>

<script type="text/javascript">
 RED.nodes.registerType('panel_led_out',{
        category: 'NK Panel LED',
        color: '#FFCC66',
        defaults: {
            name: {value:""},
            set: { value:false },
            level: { value:0},
            select: {value:"NK2200"},
            pin: {value:""},
	    enableLow: {value:""}
        },
        inputs:1,
        outputs:0,
        icon: "out.png",
        paletteLabel:"nk led",
        label: function() {
            return this.name||"nk led";
        },
        oneditprepare: function() {
            var pitype ;
            var setstate = function () {
                if ($('#node-input-set').is(":checked")) {
                    $("#node-set-state").show();
                } else {
                    $("#node-set-state").hide();
                }
            };

            $("#node-input-pin10").change(function() {                             // OP PC
              if (pitype=='NK2200') {
                var elt = document.getElementById("node-input-pin10");
                var p=document.getElementById("node-input-pin");
                p.value = elt.options[elt.selectedIndex].value;
                var txt = elt.options[elt.selectedIndex].text;
                elt = document.getElementById("node-input-name");
                elt.value = txt;
              }
            });


            var setPiType = function() {
                pitype = (document.getElementById("node-input-select")).value;
                switch (pitype) {
                  case 'NK2200':
                    $('#node-input-pin10').show();
                    $('#node-tip').hide();
                    break;
                 
                }
            };

            $("#node-input-set").change(function () { setstate(); });
            setstate();
            $('#node-input-select').change(function(){setPiType();});
            setPiType();
        }
  });    
</script>
